﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2010
// admin@franknagl.de
//
namespace SBIP.Filter
{
    /// <summary>
    /// White-Content filter.
    /// </summary>
    /// <remarks><para>The filter divides the image in two groups, 
    /// the white-content pixels and non-white-content pixels. All non-white 
    /// pixels are gray-colored with <see cref="NonWhiteContentGrayColor"/> 
    /// value. The white pixels remains unaffected.</para>
    ///	
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = new Bitmap( "cathedral.jpg" );
    ///
    /// // 1. Offline rendering of images
    /// // create Processor, used as rendering framework
    /// Processor processor = new Processor( );
    /// // starts Processor
    /// processor.Begin( image );
    /// // create WhiteContent filter
    /// WhiteContent filter = new WhiteContent( );
    /// processor.Filter = filter;
    /// // optional: configure filter
    /// ...
    /// // apply the filter, render to bitmap  
    /// Bitmap resultImage = processor.RenderToBitmap( );
    /// resultImage.Save( "WhiteContent.jpg", ImageFormat.Jpeg );
    /// // apply the filter, render to texture
    /// // Texture2D resultTexture = processor.RenderToTexture( );
    /// processor.End( );
    ///  
    /// // 2. Online rendering of videos or images
    /// // create any windows control for rendering in
    /// Form myForm = new Form
    /// {
    ///     Width = 1280,
    ///     Height = 720
    /// };
    /// // starts Processor
    /// processor.Begin( "Video.avi", myForm );
    /// // create WhiteContent filter
    /// filter = new WhiteContent( );
    /// processor.Filter = filter;
    /// // optional: configure filter
    /// ...
    /// // apply the filter
    /// myForm.Show( );
    /// while ( myForm.Created )
    /// {
    ///     processor.Render( );
    ///     Application.DoEvents( );
    /// }
    /// processor.End( );
    /// </code>
    /// 
    /// <para><b>Initial image:</b></para>
    /// <img src="../../Objects.png" />
    /// <para><b>Result image:</b></para>
    /// <img src="../../WhiteContent.png" />
    /// </remarks>
    public sealed class WhiteContent : BaseFilter
    {
        #region members        
        private bool inverted;
        private byte nonWhiteContentGrayColor;
        #endregion members

        #region properties        
        /// <summary>
        /// Determines whether filter result is drawn inverted. Default: false.
        /// </summary>
        /// <value>
        /// 	<c>true</c>, if filter result will be drawn inverted.
        /// </value>
        public bool Inverted
        {
            get { return inverted; }
            set
            {
                if (Effect == null)
                    throw new System.ArgumentException("Inverted" + InitMsg);

                inverted = value;
                Effect.Parameters["Inverted"].SetValue(value);

            }
        }

        /// <summary>
        /// The gray color value of not-white content. Default: 0.
        /// </summary>
        public byte NonWhiteContentGrayColor
        {
            get { return nonWhiteContentGrayColor; }
            set
            {
                if (Effect == null)
                    throw new System.ArgumentException("NonWhiteContentGrayColor" + InitMsg);

                nonWhiteContentGrayColor = value;
                Effect.Parameters["NonWhiteContentGrayColor"].SetValue(value / 255.0f);

            }
        }
        #endregion properties

        /// <summary>
        /// Initializes a new instance of the <see cref="WhiteContent"/> 
        /// class.
        /// </summary>        
        public WhiteContent() : base("WhiteContent") { }
    }
}
